//
//  NetDefine.h
//  FreeNet
//
//  Created by cc on 12-7-5.
//  Copyright (c) 2012年 cc. All rights reserved.
//

#ifndef _FREENET_NETDEFINE_H_CC_
#define _FREENET_NETDEFINE_H_CC_

#define __SERVER__

#define __DEBUG__

#define __SHOW_ERROR__
#define __SHOW_WARNING__
#define __SHOW_DEBUG__

//#define __LINUX__
#define __MACOSX__
//#define __IOS__

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include <pthread.h>
#include <vector>

#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#if defined (__LINUX__)
#include <epoll.h>
#elif defined (__WINDOWS__)
#elif defined (__MACOSX__)
#include <poll.h>
#elif defined (__IOS__)
#else
    #error("please select operating system\n") ;
#endif

#define __USEP2P__

namespace FreeNet {
    enum eNetMode { NET_TCP = IPPROTO_TCP, NET_UDP = IPPROTO_UDP, } ;

    struct sNetRet {
        bool bRet ;
        int  nRet ;
        float fRet ;
        char* cRet ;
    } ;

    struct sNetInfo {
        int         fd ;
        char        ip[32] ;
        int         port ;
        eNetMode    mode ;
    } ;

    // callback function pointers.
    typedef int (*NET_CALLBACK)() ;
    typedef void* (*THREAD_WORKER)(void* param) ;
    ////////////////////////////////////////////////////

    const char err_str[][128] = {
#if defined (__DEBUG__)
        [0] = "[file : %s, line : %d, function : %s], create socket error \n",
        [1] = "[file : %s, line : %d, function : %s], setsockopt error \n",
        [2] = "[file : %s, line : %d, function : %s], bind socket error \n",
        [3] = "[file : %s, line : %d, function : %s], connect socket error \n",
        [4] = "[file : %s, line : %d, function : %s], listen socket error \n",
        [5] = "[file : %s, line : %d, function : %s], accept socket error \n",
        [6] = "[file : %s, line : %d, function : %s], message queue is full \n",
#else
        [0] = "create socket error \n",
        [1] = "setsockopt error \n",
        [2] = "bind socket error \n",
        [3] = "connect server error \n",
        [4] = "listen socket error \n",
        [5] = "accept socket error \n",
        [6] = "message queue is full \n",
#endif
    } ;

#if defined (__DEBUG__)
#define showError(s)    ::printf(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define showWarning(s)  ::printf(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define showDebug(s)    ::printf(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define showError(s)    ::printf(s, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#else
#define showError(s)    ::printf("%s", s)
#define showWarning(s)  ::printf("%s", s)
#define showDebug(s)    ::printf("%s", s)
#define showError(s)    ::printf("%s", s)
#endif

}

#endif





































